//调用next(chunk)继续往下执行，参数chunk为输出内容
module.exports = function (req, res, chunk, next) {
    if (!res.contentType.startsWith('text'))
        return next(chunk);

    chunk = chunk.replace(/\/shared\.js/ig, "/shared.js?v=" + new Date().getTime());
    if (req.pathname.toLowerCase().endsWith("/js/lib/shared.js") && !req.sessionInsert) {
        chunk = "var sessionInfo = " + JSON.stringify(req.session.getAll()) + ";\r\n\r\n" + chunk;
        req.sessionInsert = true;
        return next(chunk);
    }

    return next(chunk);
};